package net.togogo.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

public class MailSender {


    public static void main(String[] args) {
        //读取配置文件
        ApplicationContext ac = new ClassPathXmlApplicationContext("mail-config.xml");
        JavaMailSender sender = (JavaMailSender) ac.getBean("mailSender");
        MimeMessage message = sender.createMimeMessage();

        try {
            //设置邮件信息对象
            MimeMessageHelper helper = new MimeMessageHelper(message,true,"utf-8");
            //设置发件人
            helper.setFrom("ja14mk@163.com");
            //设置收件人
            helper.setTo("qianminkang@togogo.net");
            //设置邮件内容
            helper.setSubject("mvc发送邮件");
            helper.setText("邮件测试");
            //开始邮件发送
            sender.send(message);
            System.out.println("发送成功！");
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }

}
